/*
    Android UIML

	Copyright (C) 2010  Bram Goffings (bramgoffings@gmail.com)

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public License
	as published by the Free Software Foundation; either version 2.1
	of	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

package uiml.android.elements;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

import uiml.android.parser.DomAndroidUimlParser;
import uiml.android.rendering.AndroidTypeDecoder;
import uiml.android.rendering.Renderer;
import uiml.android.rendering.TypeDecoder;
import android.view.View;

public class UimlDocument {
	
	private Uiml root = null;
	
	public UimlDocument(InputStream inputStream) throws ParserConfigurationException, IOException, SAXException {
		
		Document doc = new DomAndroidUimlParser(inputStream).parse();	
		Element rootElement = (Element) doc.getDocumentElement();	
		setRoot(new Uiml(rootElement));
	}

	/**
	 * @param root the root to set
	 */
	public void setRoot(Uiml root) {
		this.root = root;
	}

	/**
	 * @return the root
	 */
	public Uiml getRoot() {
		return root;
	}

	public View render() {
		Renderer renderer = new Renderer(this, TypeDecoder.getInstance(new AndroidTypeDecoder()));
		return renderer.render();
	}
}
